package cn.com.swu.mianyangapp.ui.news;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import cn.com.swu.mianyangapp.R;

public class NewsFragment extends Fragment {

    private ViewPager mViewPager;
    private TabLayout mTabLayout;
    private List<String> mTitleList;
    private List<Fragment> mFragmentList;


    private NewsControllerAdapter mNewsControllerAdapter;
    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) throws NullPointerException{

        return inflater.inflate(R.layout.fragment_news,container,false);
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mViewPager = view.findViewById(R.id.news_vp);
        mTabLayout = view.findViewById(R.id.news_tab_layout);
        initData();
        mNewsControllerAdapter = new NewsControllerAdapter(getChildFragmentManager(),mFragmentList,mTitleList);
        mViewPager.setAdapter(mNewsControllerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    private void initData() {
        mFragmentList = new ArrayList<>();
        NewsShowFragment fragment1 = NewsShowFragment.newInstance("新闻", "");
        NewsHomeFragment fragment2 = NewsHomeFragment.newInstance("我的", "");

        mFragmentList.add(fragment1);
        mFragmentList.add(fragment2);


        mTitleList = new ArrayList<>();

        mTitleList.add("新闻");
        mTitleList.add("我的");


    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }
}